#include <stdio.h>
#include <string>


char DNA2RNA[4][4][4] = {
	{{'K', 'N', 'K', 'N'}, {'T', 'T', 'T', 'T'}, {'R', 'S', 'R', 'S'}, {'I', 'I', 'M', 'I'}}, 
	{{'Q', 'H', 'Q', 'H'}, {'P', 'P', 'P', 'P'}, {'R', 'R', 'R', 'R'}, {'L', 'L', 'L', 'L'}},
	{{'E', 'D', 'E', 'D'}, {'A', 'A', 'A', 'A'}, {'G', 'G', 'G', 'G'}, {'V', 'V', 'V', 'V'}},
	{{'*', 'Y', '*', 'Y'}, {'S', 'S', 'S', 'S'}, {'*', 'C', 'W', 'C'}, {'L', 'F', 'L', 'F'}}};

int DNA2int(char a)
{
	switch (a)
	{
	case 'A': return 0;
	case 'C': return 1;
	case 'G': return 2;
	case 'T': return 3;
	}
	return 4;
}

std::string DNA2string(std::string input)
{
	int size = input.size();
	std::string result(size/3, '*');
	for (int i=0; i<result.size(); i++) {
		result[i] = DNA2RNA[DNA2int(input[3*i])][DNA2int(input[3*i+1])][DNA2int(input[3*i+2])];
	}
	return result;
}

std::string str_reverse(std::string str)
{
	std::string copy(str.c_str());
	for (int i=0; i<copy.size(); i++) {
		switch (copy[i]) {
		case 'A': copy[i] = 'T'; break;
		case 'T': copy[i] = 'A'; break;
		case 'C': copy[i] = 'G'; break;
		case 'G': copy[i] = 'C'; break;
		}
	}
	return copy;
}

int main()
{
	FILE* file = fopen("B_brevis.txt", "r");
	FILE* out = fopen("result.txt", "w");
	char* c_str = new char[6500000];
	fscanf(file, "%s", c_str);
	std::string str(c_str);
	std::string pattern = "VKLFPWFNQT";
	long result = 0;
	for (int i=0; i<str.size()-pattern.size()*3 + 1; i++) {
		std::string temp = str.substr(i, pattern.size()*3);
		std::string comp = DNA2string(temp);
		if (pattern.compare(comp) == 0)
			result++;
		std::string rev_temp = str_reverse(temp);
		std::reverse(rev_temp.begin(), rev_temp.end());
		std::string comp2 = DNA2string(rev_temp);
		if (pattern.compare(comp2) == 0)
			result++;
	}
	printf("result - %ld", &result);
	return 0;
}